package middle;

/**
 * @author 胡宇轩
 * @Email: yuxuan.hu01@bianlifeng.com
 */
public class RotateImage {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[][] d = new int[][]{{1,2,3},{4,5,6},{7,8,9}};
        int[][] o = new int[][]{{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
        solution.rotate(d);
        System.out.println(d);
    }
    static class Solution {
        public void rotate(int[][] matrix) {
            int n = matrix.length;
            for (int i = n-1; i >= n / 2; i--) {
                int startIndex = n-i-1;
                for (int j = n-i-1; j < i; j++) {
                    int t = matrix[startIndex][j];
                    matrix[startIndex][j] = matrix[n-1-j][startIndex];
                    matrix[n-1-j][startIndex] = matrix[i][n-1-j];
                    matrix[i][n-1-j] = matrix[j][i];
                    matrix[j][i] = t;
                }
            }
        }
    }
}
